package org.hxzon.workeasy.components;

import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.BeginRender;
import org.apache.tapestry5.annotations.Parameter;
import org.hxzon.workeasy.model.EasyJob;

public class JobNotifyTime {
    @Parameter
    private EasyJob job;

    @BeginRender
    void begin(MarkupWriter writer) {
        write(writer, job.getNotifyYear());
        writer.write("-");
        write(writer, job.getNotifyMonth());
        writer.write("-");
        write(writer, job.getNotifyDate());
        writer.writeRaw("<br />");
        write(writer, job.getNotifyHour());
        writer.write(":");
        write(writer, job.getNotifyMinute());
    }

    private void write(MarkupWriter writer, int num) {
        if (num == EasyJob.anyTime) {
            writer.write("*");
        } else {
            writer.write(String.valueOf(num));
        }
    }

}
